#!/bin/bash

# 定义变量
INSTALL_DIR="/usr/local/go"
GO_VERSION=1.17.3
DATA_DIR="/data/go/$GO_VERSION"

# 删除Go安装目录
remove_go_directory() {
    echo "Removing Go directory..."
    if [ -d "$INSTALL_DIR" ]; then
        sudo rm -rf "$INSTALL_DIR" "$DATA_DIR"
        echo "Go directory removed."
    else
        echo "Go directory not found."
    fi
}

# 清除环境变量
clear_environment_variables() {
    echo "Clearing environment variables..."
    if [ -f /etc/profile.d/go.sh ]; then
        sudo rm /etc/profile.d/go.sh
        sudo source /etc/profile
        echo "Environment variables cleared."
    else
        echo "Go environment variables not found."
    fi
}

# 主函数
main() {
    remove_go_directory
    clear_environment_variables
    echo "Go has been successfully uninstalled."
}

# 运行主函数
main
